<template>
  <el-dialog title="磅重信息"
             :visible.sync="dialogForm"
             width="560px">
    <el-form :inline="true"
             ref="form"
             :model="form"
             :rules="rules"
             class="add-form"
             label-width="110px">
      <el-row>
        <el-col>
          <el-form-item label="磅次"
                        prop="lbsTimes">
            <el-input type="text"
                      placeholder="请输入内容"
                      :maxLength="$maxLength"
                      :disabled="disabled"
                      v-model="form.lbsTimes"></el-input>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="合磅重量"
                        prop="lbsWeight">
            <el-input type="text"
                      placeholder="请输入内容"
                      :maxLength="$maxLength"
                      :disabled="disabled"
                      v-model="form.lbsWeight"></el-input>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="跟踪号"
                        prop="trackingNo">
            <el-input type="text"
                      placeholder="请输入内容"
                      :maxLength="$maxLength"
                      v-model="form.trackingNo"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer"
         class="dialog-footer">
      <el-button type="primary"
                 @click="handleSubmit">确 定</el-button>
      <el-button @click="dialogForm = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  PUBLIC_NUMBER,
  PUBLIC_NUM_CODE,
  REG_LETTER_NUM_POINT,
  PUBLIC_INT_NULL,
  REG_NUMBER
} from '@/utils/Reg'
import { maxLength, sortLength } from '@/utils/rules'

export default {
  name: 'addListForm',
  data() {
    return {
      form: this.clearForm(),
      dialogForm: false,
      disabled:false,
      rules: {
        lbsTimes: [
          { required: true, message: '请输入磅次', trigger: 'change' }
        ],
        lbsWeight: [
          { required: true, message: '请输入合磅重量', trigger: 'change' },
          {
            pattern: PUBLIC_NUMBER,
            message: '只能输入整数或者小数',
            trigger: 'change'
          }
        ],
         trackingNo: [
          { required: true, message: '请录入跟踪号', trigger: 'change' },
          { pattern: REG_NUMBER, message: '只能输入整数', trigger: 'change' }
        ],
      }
    }
  },
  methods: {
    clearForm() {
      return {
        lbsTimes: null,
        lbsWeight: null,
        trackingNo: null
      }
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('load', this.form)
        } else {
          this.$message({
            message: '请检查表单',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
